home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / ARASAN_S.ZIP / SEARCH.H < prev    next >
C/C++ Source or Header  |  1994-07-31  |  4KB  |  179 lines

  1. // Copyright 1994 by Jon Dart.  All Rights Reserved.
  2.  
  3. #ifndef _SEARCH_H
  4. #define _SEARCH_H
  5.  
  6. #include "board.h"
  7. #include "emove.h"
  8. #include "pinfo.h"
  9. #include "hash.h"
  10. #include "timectrl.h"
  11. #include "movegen.h"
  12. #include <time.h>
  13. #ifdef WINDOWS
  14. #include <windows.h>
  15. #endif
  16.  
  17. class ReversibleMove;
  18.  
  19. class Search
  20. {
  21.     // Encapsulates alpha-beta search routine.
  22.  
  23.     public:
  24.     
  25.     enum StateType {Normal,Terminated,Check,Checkmate,
  26.                 Stalemate,Draw,Resigns};
  27.  
  28.     struct Statistics
  29.     {
  30.        StateType state;
  31.        int value;
  32.        Move best_line[Constants::MaxPly];
  33.        time_t elapsed_time;
  34.        unsigned plies_completed;
  35.        unsigned max_depth;
  36.        unsigned long num_moves;
  37.        unsigned long num_pos;
  38.        Statistics();
  39.        void clear();
  40.     };
  41.     
  42.     Search();
  43.     
  44.     ~Search();
  45.     
  46.     void terminate_now();
  47.     
  48.     Move find_best_move( 
  49. #ifdef WINDOWS
  50.         HWND hWnd,
  51. #endif
  52.         const Board &ABoard, 
  53.         const Time_Info &ti,
  54. #ifdef WINDOWS            
  55.         const Boolean background,
  56. #endif            
  57.         Statistics &stats,
  58.         Move &prev_move,
  59.             Boolean use_previous_search );
  60.     
  61.     unsigned hints( const Board &ABoard,
  62.         Move *moves,
  63.         unsigned max_moves);
  64.     // fill "moves" with up to "max_moves" hint moves, computed using
  65.     // a minimal search depth.        
  66.         
  67.     int get_ply() const;
  68.     // return current depth of search.
  69.  
  70.     unsigned long get_numpos() const;
  71.     // return # of positions evaluated
  72.         
  73.     time_t get_start_time() const
  74.     {
  75.         return start_time;
  76.     }
  77.     
  78.     Search_Type get_search_type() const
  79.     {
  80.     return timeCtrl.get_search_type();
  81.     }
  82.     
  83.     Search_Limit get_search_limit() const
  84.     {
  85.     return timeCtrl.get_search_limit();
  86.     }
  87.     
  88.     ColorType get_side_to_move() const
  89.     {
  90.     return side_to_move;
  91.     }
  92.     
  93.     Boolean is_background_search() const
  94.     {
  95.     return bkgrnd_search;
  96.     }
  97.     
  98.     void set_time_up( const Boolean b )
  99.     {
  100.     time_up = b;
  101.     }
  102.     
  103.     Boolean was_terminated() const
  104.     {
  105.     return terminated;
  106.     }
  107.     
  108.     unsigned long get_time_limit() const
  109.     { 
  110.         return time_target;
  111.     }
  112.  
  113. private:
  114.     // make this class uncopyable:
  115.     Search( const Search & );
  116.     Search &operator = ( const Search & );
  117.  
  118.     int move_search(Board & ABoard, int alpha, int beta,
  119.         const int ply, const Boolean princip_var,
  120.         Boolean &terminate, Move *best_line);
  121.         Boolean skip_move(const Board & ABoard, const unsigned ply,
  122.       const unsigned limit,
  123.       const ExtendedMove & emove, const Boolean in_check);
  124.         int try_move(Board & ABoard, const ExtendedMove & emove,
  125.       const int ply, int alpha, int &beta, const int rank,
  126.       const Boolean pv, const Boolean forced,
  127.       Boolean &terminate, Move *best_line);
  128.         unsigned generate_moves(
  129.            Board & board, Move_Generator & mg,
  130.            const unsigned ply,
  131.            Move * moves,
  132.            const Boolean captures_only);
  133.         int evalu8(const Board & board);
  134.     Boolean is_draw( const Board &board, int &rep_count );
  135.  
  136.     unsigned long num_moves;
  137.     unsigned plies_done;
  138.     Move ply0moves[Move_Generator::MaxMoves];
  139.     int ply0scores[Move_Generator::MaxMoves];
  140.     int ply0move_count;
  141.     int rank; // moves completed at ply 0
  142.     Boolean ply0moves_generated;
  143.     ExtendedMove *last_move; // array, size MaxPly
  144.     Move *best_moves; // array, size MaxPly.  Best move at
  145.               // each ply
  146.         int best_scores[Constants::MaxPly];                   
  147.     Move *pv;         // array, size MaxPly
  148.     ReversibleMove *move_stack[Constants::MaxPly];
  149.     Move *moves_generated[Constants::MaxPly]; // MaxMoves for each ply
  150.     Move *candidates[Constants::MaxPly]; // MaxPly for each ply
  151.     Boolean forced[Constants::MaxPly];
  152.     Hash < Position_Info > *hash_table;
  153.     int extend;
  154.     Search::StateType state;
  155.     ColorType side_to_move;
  156.     Boolean terminated;
  157.     Boolean bkgrnd_search;
  158.     unsigned long time_target, time_added;
  159.  
  160. #ifdef WINDOWS
  161.     int search_number;
  162.     static HACCEL accel;
  163.     HWND my_hwnd;
  164.     UINT idTimer;
  165. #endif
  166.     time_t start_time;
  167.     Time_Control timeCtrl;
  168.     unsigned long num_pos;
  169.     int max_depth; // nominal search limit
  170.     int display_depth; // depth to display
  171.     Boolean time_up, searching;
  172. #ifdef NULL_MOVE
  173.     Boolean null_move;
  174. #endif
  175. };
  176.  
  177. #endif
  178.  
  179.